import Mock from "mockjs"
import { param2Obj } from "../utils/url"

let List = [];
for (var i = 0; i < 200; i++) {
    List.push({
        order_reference: Mock.mock('@id'),
        orders: "课程订单",
        caption: Mock.mock("@integer(0,3)"),
        order_amount: "￥" + Mock.mock("@integer(5000,20000)"),
        order_status: Mock.mock("@integer(0,1)"),
        order_time: Mock.mock('@datetime')
    }, )
}

export default {
    // 首屏、搜索、分页
    getFinanceData: (config) => {
        // console.log("config", param2Obj(config.url));
        let { search, page, pageSize } = param2Obj(config.url)
        let newList = List.filter(item => {
            return item.order_reference.indexOf(search) != -1
        })

        // 分页
        let newList2 = newList.filter((item, index) => {
            return (page - 1) * pageSize <= index && index < page * pageSize
        })
        if (newList2.length == 0) {
            page--
            newList2 = newList.filter((item, index) => {
                return (page - 1) * pageSize <= index && index < page * pageSize
            })
        }
        return {
            code: 200,
            msg: "请求成功",
            data: newList2,
            total: List.length,
            page: page
        }
    },
    // 批量删除
    batchDelateData: (config) => {
        // console.log("config", JSON.parse(config.body));
        let { ids } = JSON.parse(config.body)
        let newList = List.filter(item => {
            return ids.indexOf(item.order_reference) === -1
        })
        List = newList
        return {
            code: 200,
            msg: "批量删除",
            data: null
        }
    }
}